package com.stone.business.sbqxjl.action;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileInputStream;
import com.stone.business.gzrwd.service.ZbjlCommonService;

import frm.ssh.action.BaseAction;
import frm.ssh.exception.AppException;

public class PhotoAttachAction extends BaseAction {
	// 下载用 返回的文件流
	protected InputStream returnStream;
	// 下载用的名字
	protected String downFileName;
	protected String id;
	private ZbjlCommonService tabPhotoService;
	

	
	public ZbjlCommonService getTabPhotoService() {
		return tabPhotoService;
	}
	public void setTabPhotoService(ZbjlCommonService tabPhotoService) {
		
		this.tabPhotoService = tabPhotoService;
	}
	
	
    public SmbFileInputStream smbGet1(String remoteUrl) throws IOException {    
        SmbFile smbFile = new SmbFile(remoteUrl);    
        int length = smbFile.getContentLength();// 得到文件的大小    
        byte buffer[] = new byte[length];    
        SmbFileInputStream in = new SmbFileInputStream(smbFile);   
        return in;   
    }    



	/**下载
	 * 
	 * @return
	 * @throws AppException
	 * @throws IOException 
	 */
	public String fileDownload() throws  IOException {
	
		
	//	TabTestreportattach entity = (TabTestreportattach) tabTestitemsService.findById(Long
	//			.parseLong(this.id), TabTestreportattach.class.getName());
		this.smbGet1("smb://administrator:nsrapw369@10.141.162.39/XTBGJX/model/JXKH.xls ");
		this.returnStream = this.smbGet1("smb://administrator:pass@10.1.32.44/fff/食品处发言稿.pdf ");
		downFileName =  "检验报告.pdf";
		
		return "download";
	}
	 public static void main(String[] args)   
    {   
		 PhotoAttachAction test = new PhotoAttachAction();   
	        // smb:域名;用户名:密码@目的IP/文件夹/文件名.xxx   
       // test.smbGet("smb://szpcg;jiang.t:xxx@192.168.193.13/Jake/test.txt",   
	       // "c://") ;   
	          
     //test.smbPut("smb://szpcg;jiang.t:xxx@192.168.193.13/Jake","c://test.txt");   
	                  
     //用户名密码不能有强字符，也就是不能有特殊字符，否则会被作为分断处理   
    // test.smbGet("smb://CHINA;xieruilin:123456Xrl@10.70.36.121/project/report/网上问题智能分析助手使用文档.doc", "c://Temp/");   
		 try {
			test.smbGet1("smb://administrator:nsrapw369@10.141.162.39/XTBGJX/model/JXKH.xls ");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
   }   

	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public InputStream getReturnStream() {
		return returnStream;
	}
	public void setReturnStream(InputStream returnStream) {
		this.returnStream = returnStream;
	}
	public String getDownFileName() throws Exception {
		downFileName = new String(downFileName.getBytes(), "ISO8859-1");
		return downFileName;
	}
	public void setDownFileName(String downFileName) {
		this.downFileName = downFileName;
	}
}
